<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta charset="UTF-8">
    <th:block th:include="include :: header('新增企业基本信息')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-corp-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">企业名称：</label>
            <div class="col-sm-8">
                <select class="form-control" name="deptId" id="deptName" required>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">统一社会信用代码：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" autocomplete="off" name="tyshxydm" id="tyshxydm" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">厂商码信息：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" autocomplete="off" name="corpCode" id="corpCode" required>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
    $(function (){
        $.ajax({
            url:"/base/getdept",
            type:"get",
            dataType:"json",
            success:function (res){
                $("#deptName").empty();
                $.each(res,function (i,o) {
                    $("#deptName").append('<option value="'+o.deptId+'">'+o.deptName+'</option>');
                })
            }
        })
        $("#form-corp-add").validate({
            onkeyup: false,
            rules:{
                deptId:{
                    remote: {
                        url: "/base/checkDeptNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "deptName" : function() {
                                return $.common.trim(parseInt($("#deptName").val()));
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                tyshxydm:{
                    remote: {
                        url: "/base/checkTyshxydmNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "tyshxydm" : function() {
                                return $.common.trim($("#tyshxydm").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                corpCode:{
                    remote: {
                        url: "/base/checkCorpCodeUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "corpCode" : function() {
                                return $.common.trim($("#corpCode").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
            },
            messages: {
                "deptId": {
                    remote: "企业名已经存在"
                },
                "tyshxydm": {
                    remote: "统一社会信用代码已经存在"
                },
                "corpCode": {
                    remote: "厂商码已经存在"
                }
            },
            focusCleanup: true
        });
    })

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save("/base/corp_add", $('#form-corp-add').serialize());
        }
    }
</script>
</body>
</html>